package com.huawei.appmarket.service.externalapi.actions;

import android.app.Activity;
import android.content.Context;
import androidx.annotation.NonNull;
import java.lang.ref.WeakReference;
import o.awo;
import o.AccountBussinessListener;
import o.ccp;
import o.dhq;
import o.diq;
import o.diu;
import o.Logger;
import o.dyr;
import o.dys.a;
import o.eod;
import o.eoj;
import o.eqn;
import o.eqq;

public class CheckProtocolWithUpdateAction extends dyr implements AccountBussinessListener, eqn {
    private static final String TAG = "CheckProtocolWithUpdateAction";

    static class b extends diq implements awo {
        private WeakReference<a> ˏ;

        private b(a aVar) {
            this.ˏ = new WeakReference(aVar);
        }

        public void ˎ(Activity activity) {
            Logger.ˎ(CheckProtocolWithUpdateAction.TAG, "onSign agreement");
            super.ˎ(activity);
            ॱ(true);
        }

        public void ˋ(boolean z) {
            Logger.ˎ(CheckProtocolWithUpdateAction.TAG, "onCheckResult, isAgreeProGlobal=" + z);
            if (z) {
                dhq.ॱ().ˋ();
            } else {
                dhq.ॱ().ˊ();
            }
            ॱ(z);
        }

        private void ॱ(boolean z) {
            a aVar;
            if (this.ˏ != null) {
                aVar = (a) this.ˏ.get();
            } else {
                aVar = null;
            }
            if (aVar == null) {
                Logger.ˋ(CheckProtocolWithUpdateAction.TAG, "setResult, callback == NULL");
                return;
            }
            aVar.setResult(z ? 1001 : 1002);
            aVar.finish();
        }
    }

    public CheckProtocolWithUpdateAction(a aVar) {
        super(aVar);
    }

    public boolean isNeedLoading() {
        return true;
    }

    private Activity getActivity() {
        if (this.callback instanceof Activity) {
            return (Activity) this.callback;
        }
        return null;
    }

    public void onAction() {
        Context activity = getActivity();
        if (activity == null) {
            Logger.ˋ(TAG, "onAction, !callback instanceof Activity");
            return;
        }
        eoj.ˋ().ˎ(TAG, this);
        eqq.ˋ().ˎ(TAG, this);
        eod.ॱ(activity);
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        eoj.ˋ().ˊ(TAG);
        Activity activity = getActivity();
        if (activity == null || activity.isFinishing()) {
            Logger.ˋ(TAG, "onAccountBusinessResult, activity is null or is finishing");
        } else if (102 == o_ccp.ˎ) {
            onLoginSuccess(activity);
        } else {
            Logger.ˋ(TAG, "onAccountBusinessResult, resultCode: " + o_ccp.ˎ);
            setErrorResult();
        }
    }

    private void onLoginSuccess(@NonNull Activity activity) {
        Logger.ˎ(TAG, "onLoginSuccess");
        if (diq.ॱ()) {
            Logger.ˋ(TAG, "onLoginSuccess, query is running, abort request.");
            setErrorResult();
            return;
        }
        Object bVar = new b(this.callback);
        diu.ˊ().ॱ(activity, bVar, bVar);
    }

    private void setErrorResult() {
        Logger.ˎ(TAG, "setErrorResult");
        setCallbackResult(diu.ˊ().ˎ());
    }

    public void onResult(int i) {
        eqq.ˋ().ˊ(TAG);
        Logger.ˎ(TAG, "login flow onResult:" + i);
        if (201 == i) {
            setCallbackResult(false);
        }
    }

    private void setCallbackResult(boolean z) {
        Logger.ˎ(TAG, "setCallbackResult :" + z);
        if (this.callback == null) {
            Logger.ˋ(TAG, "callback == null");
            return;
        }
        this.callback.setResult(z ? 1001 : 1002);
        this.callback.finish();
    }
}
